package cn.com.infohold.smartcity.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import cn.com.infohold.smartcity.R;
import cn.com.infohold.smartcity.activity.Fabaofang.FaBaoFangDetail_Activity;
import cn.com.infohold.smartcity.api.bean.FaBaoFangBean;
import cn.com.infohold.smartcity.parent.ParentActivity;

/**
 * Created by Monsoon on 2017/11/3.
 */
public class Fabaofang_Adapter extends RecyclerView.Adapter<Fabaofang_Adapter.mViewHolder>{

    private Context context;
    private List<FaBaoFangBean> mList;

    public Fabaofang_Adapter(Context context, List<FaBaoFangBean> mList) {
        this.context = context;
        this.mList = mList;
    }

    @Override
    public mViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mViewHolder viewHolder = new mViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_fabaofang, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(mViewHolder holder, int position) {

        FaBaoFangBean bean = mList.get(position);

        holder.tv_code.setText(bean.getCode());
        holder.tv_shortname.setText(bean.getShortname());
        holder.tv_name.setText(bean.getFullname());
        holder.tv_zipcode.setText(bean.getZipcode());
        holder.tv_wheelman.setText(bean.getWheelman());

        holder.ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,FaBaoFangDetail_Activity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("fb_detail",bean);
                intent.putExtra("fb_bundle",bundle);
                context.startActivity(intent);
                ((ParentActivity)context).overridePendingTransitionFade();
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class mViewHolder extends RecyclerView.ViewHolder{
        LinearLayout ll_item;
        TextView tv_code;
        TextView tv_shortname;
        TextView tv_name;
        TextView tv_zipcode;
        TextView tv_wheelman;

        public mViewHolder(View itemView) {
            super(itemView);
            ll_item = (LinearLayout) itemView.findViewById(R.id.ll_item);
            tv_code = (TextView) itemView.findViewById(R.id.tv_code);
            tv_shortname = (TextView) itemView.findViewById(R.id.tv_shortname);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_zipcode = (TextView) itemView.findViewById(R.id.tv_zipcode);
            tv_wheelman = (TextView) itemView.findViewById(R.id.tv_wheelman);
        }
    }
}
